|
|
|
|
|
|
|
If you use a COUNTER data type field in your table, you can't include that in the field list of the INSERT INTO statement. Visual Basic and the SQL engine fill the COUNTER field with an appropriate value. Also, you do not have to add data to every column in the row. If there are fields in the data table that are not required and that can be left null, you can simply omit them from the INSERT INTO statement. The code example in Listing 15.2 illustrates these last two points. Use SQL-VB5 to edit the SQLVB05.SQV script to match the one in Listing 15.2. Save and execute the script. Check your results against those in Figure 15.2. |
|
|
|
|
|
|
|
|
Listing 15.2. Handling COUNTER and blank fields in INSERT statements. |
|
|
|
|
|
|
|
|
//
// sqlvb05.sqv - Testing the INSERT INTO keyword
//
// create a new database
dbMake sqlvb05.mdb;
// create a new table
CREATE TABLE JobTitles
(JobCounter COUNTER,
JobID TEXT(5) CONSTRAINT PKJobTitle PRIMARY KEY,
JobName TEXT(20),
JobPay CURRENCY,
JobDesc MEMO
);
// insert some data
INSERT INTO JobTitles (JobID, JobName, JobDesc, JobPay) VALUES
('J001',
'President',
'Presides over the company',
'50000'
);
INSERT INTO JobTitles (JobID, JobName, JobDesc, JobPay) VALUES
('J002',
'Vice President',
'Does what the President tells him to do',
'40000'
);
INSERT INTO JobTitles (JobID, JobPay, JobName) VALUES
('J003',
'35000',
'Chief Engineer'
);
// display results
SELECT * FROM JobTitles;
// eof |
|
|
|
|
|
|
|
|
Notice that the JobTitles.JobCounter column was automatically populated by Visual Basic. Also, you can see that the JobTitles.JobDesc column was left blank for the third record in the table. |
|
|
|
|
|